package cn.agiledata.bank.common.util;

import java.lang.reflect.Field;

public class CurrencyType {
    /**
     * 人民币（国标）
     */
    public static final CurrencyType CNY = new CurrencyType("CNY", "人民币");

    /**
     * 人民币（常用）
     */
    public static final CurrencyType RMB = new CurrencyType("RMB", "人民币");

    /**
     * 美元
     */
    public static final CurrencyType USD = new CurrencyType("USD", "美元");

    /**
     * 日元
     */
    public static final CurrencyType JPY = new CurrencyType("JPY", "日元");

    /**
     * 欧元
     */
    public static final CurrencyType EUR = new CurrencyType("EUR", "欧元");

    /**
     * 英镑
     */
    public static final CurrencyType GBP = new CurrencyType("GBP", "英镑");

    /**
     * 德国马克
     */
    public static final CurrencyType DEM = new CurrencyType("DEM", "德国马克");

    /**
     * 瑞士法郎
     */
    public static final CurrencyType CHF = new CurrencyType("CHF", "瑞士法郎");

    /**
     * 法国法郎
     */
    public static final CurrencyType FRF = new CurrencyType("FRF", "法国法郎");

    /**
     * 加拿大元
     */
    public static final CurrencyType CAD = new CurrencyType("CAD", "加拿大元");

    /**
     * 澳大利亚元
     */
    public static final CurrencyType AUD = new CurrencyType("AUD", "澳大利亚元");

    /**
     * 港币
     */
    public static final CurrencyType HKD = new CurrencyType("HKD", "港币");

    /**
     * 奥地利先令
     */
    public static final CurrencyType ATS = new CurrencyType("ATS", "奥地利先令");

    /**
     * 芬兰马克
     */
    public static final CurrencyType FIM = new CurrencyType("FIM", "芬兰马克");

    /**
     * 比利时法郎
     */
    public static final CurrencyType BEF = new CurrencyType("BEF", "比利时法郎");

    /**
     * 爱尔兰镑
     */
    public static final CurrencyType IEP = new CurrencyType("IEP", "爱尔兰镑");

    /**
     * 意大利里拉
     */
    public static final CurrencyType ITL = new CurrencyType("ITL", "意大利里拉");

    /**
     * 卢森堡法郎
     */
    public static final CurrencyType LUF = new CurrencyType("LUF", "卢森堡法郎");

    /**
     * 荷兰盾
     */
    public static final CurrencyType NLG = new CurrencyType("NLG", "荷兰盾");

    /**
     * 葡萄牙埃斯库多
     */
    public static final CurrencyType PTE = new CurrencyType("PTE", "葡萄牙埃斯库多");

    /**
     * 西班牙比塞塔
     */
    public static final CurrencyType ESP = new CurrencyType("ESP", "西班牙比塞塔");

    /**
     * 印尼盾
     */
    public static final CurrencyType IDR = new CurrencyType("IDR", "印尼盾");

    /**
     * 马来西亚林吉特
     */
    public static final CurrencyType MYR = new CurrencyType("MYR", "马来西亚林吉特");

    /**
     * 新西兰元
     */
    public static final CurrencyType NZD = new CurrencyType("NZD", "新西兰元");

    /**
     * 菲律宾比索
     */
    public static final CurrencyType PHP = new CurrencyType("PHP", "菲律宾比索");

    /**
     * 俄罗斯卢布
     */
    public static final CurrencyType SUR = new CurrencyType("SUR", "俄罗斯卢布");

    /**
     * 新加坡元
     */
    public static final CurrencyType SGD = new CurrencyType("SGD", "新加坡元");

    /**
     * 韩元
     */
    public static final CurrencyType KRW = new CurrencyType("KRW", "韩元");

    /**
     * 泰铢
     */
    public static final CurrencyType THB = new CurrencyType("THB", "泰铢");

    private String code;

    private String name;

    private CurrencyType(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public static CurrencyType getCurrenctyType(String code) {
        if (code == null || code.length() != 3)
            return null;
        Field[] fields = CurrencyType.class.getFields();
        for (int i = 0; i < fields.length; i++) {
            if (fields[i].getType().equals(CurrencyType.class)) {
                try {
                    CurrencyType type = (CurrencyType) fields[i].get(null);
                    if (type.getCode().equals(code))
                        return type;
                } catch (IllegalArgumentException e) {
                } catch (IllegalAccessException e) {
                }
            }
        }
        return null;
    }

    public String getName() {
        return this.name;
    }

    public String getCode() {
        return this.code;
    }

    public String toString() {
        return this.getName() + "(" + this.getCode() + ")";
    }

}
